package com.onpositive.realmview.basic;

import java.util.HashMap;
import java.util.Map;

import com.onpositive.semantic.model.api.command.ICommandExecutor;
import com.onpositive.semantic.model.api.property.IProperty;
import com.onpositive.semantic.model.api.property.IPropertyProvider;
import com.onpositive.semantic.model.api.property.IValueListener;
import com.onpositive.semantic.model.realm.IRealm;

public class ProxyMapPropertyProvider implements IPropertyProvider {
	
	protected final IPropertyProvider originalPropertyProvider;
	protected final Map<String, Object> valueMap;
	protected final Map<String, IProperty> proxyProps = new HashMap<String, IProperty>();
	private IListenableCommandExecutor commandExecutor;

	public ProxyMapPropertyProvider(IPropertyProvider originalPropertyProvider, Object originalObject, Map<String,Object> valueMap) {
		this.originalPropertyProvider = originalPropertyProvider;
		this.valueMap = valueMap;
		
		Iterable<IProperty> properties = originalPropertyProvider.getProperties(originalObject);
		for (IProperty property : properties) {
			proxyProps.put(property.getId(), new ProxyMapProperty(property.getId(),property.getSubjectClass(),property.getPropertyMetaData(),valueMap));
		}
	}

	@Override
	public IProperty getProperty(Object obj, String name) {
		return proxyProps.get(name);
	}

	@Override
	public Iterable<IProperty> getProperties(Object obj) {
		return proxyProps.values();
	}

	@Override
	public void addValueListener(Object obj, IValueListener<Object> listener) {
		// TODO Auto-generated method stub

	}

	@Override
	public void removeValueListener(Object obj, IValueListener<Object> listener) {
		// TODO Auto-generated method stub

	}

	@Override
	public void registerRealm(IRealm<?> realm, IValueListener<Object> listener) {
		// TODO Auto-generated method stub

	}

	@Override
	public void unregisterRealm(IRealm<?> realm, IValueListener<Object> listener) {
		// TODO Auto-generated method stub

	}

	@Override
	public ICommandExecutor getCommandExecutor() {
		if (commandExecutor == null)
			commandExecutor = new ProxyMapCommandExecutor(valueMap);
		return commandExecutor;
	}

}
